﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Telerik.Web.UI;

public partial class main_dataReport_year : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            RadGrid1.Visible = false;
            LinkButton2.Visible = false;
            LineDAOs lineDAOs = LineDAOs.getInstance();
            List<String> lineList = lineDAOs.getLineNameList();
            for (int i = 0; i < lineList.Count; i++)
            {
                DropDownList1.Items.Add(lineList[i]);
            }

            for (int i = Common.MINYEAR; i <= Common.MAXYEAR; i++)
            {
                DropDownList2.Items.Add(i+"");
            }
        }
    }

    protected void RadGrid1_PageIndexChanged(object source, GridPageChangedEventArgs e)
    {
        RadGrid1.CurrentPageIndex = e.NewPageIndex;
        UpdateGridView();
    }
    protected void RadGrid1_PageSizeChanged(object source, GridPageSizeChangedEventArgs e)
    {
        UpdateGridView();
    }

    protected void UpdateGridView()
    {
        DataTable dataTable;
        DateTime begin = new DateTime(Int32.Parse(DropDownList2.SelectedValue), 1, 1);
        DateTime end = new DateTime(Int32.Parse(DropDownList2.SelectedValue)+1, 1, 1);
        LineDAOs lineDAOs = LineDAOs.getInstance();
        dataTable = lineDAOs.getYearReport(DropDownList1.SelectedValue, begin, end);
        

        RadGrid1.DataSource = dataTable;
        RadGrid1.DataBind();

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {

        UpdateGridView();
        RadGrid1.Visible = true;
        LinkButton2.Visible = true;
       
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        if (RadGrid1.Visible == true)
        {
            RadGrid1.ExportSettings.ExportOnlyData = false;
            RadGrid1.ExportSettings.IgnorePaging = true;

            UpdateGridView();
            RadGrid1.MasterTableView.ExportToCSV();
        }

    }
}
